'\" t
.\"     Title: modbus_send_raw_request
.\"    Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\"      Date: 10/06/2013
.\"    Manual: Libmodbus Manual
.\"    Source: libmodbus 3.0.4
.\"  Language: English
.\"
.TH "MODBUS_SEND_RAW_REQU" "3" "10/06/2013" "libmodbus 3\&.0\&.4" "Libmodbus Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
modbus_send_raw_request \- send a raw request
.SH "SYNOPSIS"
.sp
\fBint modbus_send_raw_request(modbus_t *\fR\fB\fIctx\fR\fR\fB, uint8_t *\fR\fB\fIraw_req, int \*(Aqraw_req_length\fR\fR\fB);\fR
.SH "DESCRIPTION"
.sp
The \fImodbus_send_raw_request()\fR function shall send a request via the socket of the context \fIctx\fR\&. This function must be used for debugging purposes because you have to take care to make a valid request by hand\&. The function only adds to the message, the header or CRC of the selected backend, so \fIraw_req\fR must start and contain at least a slave/unit identifier and a function code\&. This function can be used to send request not handled by the library\&.
.SH "RETURN VALUE"
.sp
The \fImodbus_send_raw_request()\fR function shall return the full message length, counting the extra data relating to the backend, if successful\&. Otherwise it shall return \-1 and set errno\&.
.SH "EXAMPLE"
.sp
.if n \{\
.RS 4
.\}
.nf
modbus_t *ctx;
/* Read 5 holding registers from address 1 */
uint8_t raw_req[] = { 0xFF, 0x03, 0x00, 0x01, 0x0, 0x05 };
int req_length;
uint8_t rsp[MODBUS_TCP_MAX_ADU_LENGTH];

ctx = modbus_new_tcp("127\&.0\&.0\&.1", 1502);
if (modbus_connect(ctx) == \-1) {
    fprintf(stderr, "Connection failed: %s\en", modbus_strerror(errno));
    modbus_free(ctx);
    return \-1;
}

req_length = modbus_send_raw_request(ctx, raw_req, 6 * sizeof(uint8_t));
modbus_receive_confirmation(ctx, rsp);

modbus_close(ctx);
modbus_free(ctx);
.fi
.if n \{\
.RE
.\}
.SH "SEE ALSO"
.sp
\fBmodbus_receive_confirmation\fR(3)
.SH "AUTHORS"
.sp
The libmodbus documentation was written by St\('ephane Raimbault <\m[blue]\fBstephane\&.raimbault@gmail\&.com\fR\m[]\&\s-2\u[1]\d\s+2>
.SH "NOTES"
.IP " 1." 4
stephane.raimbault@gmail.com
.RS 4
\%mailto:stephane.raimbault@gmail.com
.RE
